package com.todo.dao;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.todo.dto.TeamMemberDTO;
import com.todo.entity.TeamInfo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

@Data
@TableName(value = "t_full_info")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class TeamInfoDAO implements Serializable {

    @TableId(value = "tid")
    private String tid;

    /**
     * 所有者uid
     */
    private String tOwner;

    /**
     *成员列表 将java对象转换为json字符串进行存储
     */
    private String tMemberList;


    private LocalDateTime createTime;

    private LocalDateTime updateTime;

    public TeamInfo toTeamInfo(){
        TeamInfo teamInfo = new TeamInfo();
        teamInfo.setTid(this.tid);
        teamInfo.setTOwner(this.tOwner);
        //将json字符串转为对象存入实体类中
        //获取json字符串
        String memberList = this.tMemberList;
        //json字符串转java对象
        List<TeamMemberDTO> teamInfoDAOList = JSONObject.parseArray(memberList,TeamMemberDTO.class);
        teamInfo.setTMemberCount(teamInfoDAOList.size());
        teamInfo.setTMemberList(teamInfoDAOList);
        teamInfo.setCreateTime(this.createTime);
        teamInfo.setUpdateTime(this.updateTime);
        return teamInfo;
    }

}
